'use strict';
// **Github:** https://github.com/toajs/toa
//
// modified from https://github.com/koajs/koa/tree/master/test
//
// **License:** MIT
/*global describe, it, before, after, beforeEach, afterEach*/

/*jshint -W124 */

var assert = require('assert');
var request = require('../context').request;

describe('req.ip', function() {
  describe('with req.ips present', function() {
    it('should return req.ips[0]', function() {
      var req = request();
      req.ctx.config.proxy = true;
      req.header['x-forwarded-for'] = '127.0.0.1';
      req.socket.remoteAddress = '127.0.0.2';
      assert(req.ip === '127.0.0.1');
    });
  });

  describe('with no req.ips present', function() {
    it('should return req.socket.removeAddress', function() {
      var req = request();
      req.socket.remoteAddress = '127.0.0.2';
      assert(req.ip === '127.0.0.2');
    });
  });
});
